package 线程安全问题;

class Bank{
	private int id;
	private int money;
	public Bank(int id, int money) {
		super();
		this.id = id;
		this.money = money;
	}
	public synchronized void getmoney(int money1)
	{
		String nameString=Thread.currentThread().getName();
		if(this.money>=money1)
		{
			System.out.println(nameString+"来取钱"+money1+"成功");
			this.money-=money1;
			System.out.println(nameString+"来取钱后,余额剩余"+this.money);
		}
		else
			System.out.println(nameString+"来取钱，余额不足");
		}		
}
class my extends Thread{
	private Bank bank;
	public my(Bank bank,String name) {
		super(name);
		this.bank = bank;
	}

	public void run()
	{
		bank.getmoney(10000);
	}
}
public class MyThread {
	public static void main(String [] args) throws Exception {
		Bank bank=new Bank(1111100,10000);
		Thread thread=new my(bank, "李华");
		Thread thread2=new my(bank,"小红");
		thread.start();
		thread2.start();
	}
}